package com.ruoyi.project.jiaqin.numbertips.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.numbertips.domain.NumberTips;
import com.ruoyi.project.jiaqin.numbertips.service.INumberTipsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数字提示Controller
 *
 * @author LCL
 * @date 2022-01-12
 */
@Controller
@RequestMapping("/jiaqin/numbertips")
public class NumberTipsController extends BaseController
{
    private String prefix = "jiaqin/numbertips";

    @Autowired
    private INumberTipsService numberTipsService;

    @RequiresPermissions("jiaqin:numbertips:view")
    @GetMapping()
    public String numbertips()
    {
        return prefix + "/numbertips";
    }

    /**
     * 查询数字提示列表
     */
    @RequiresPermissions("jiaqin:numbertips:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NumberTips numberTips)
    {
        startPage();
        List<NumberTips> list = numberTipsService.selectNumberTipsList(numberTips);
        return getDataTable(list);
    }

    /**
     * 导出数字提示列表
     */
    @RequiresPermissions("jiaqin:numbertips:export")
    @Log(title = "数字提示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NumberTips numberTips)
    {
        List<NumberTips> list = numberTipsService.selectNumberTipsList(numberTips);
        ExcelUtil<NumberTips> util = new ExcelUtil<NumberTips>(NumberTips.class);
        return util.exportExcel(list, "numbertips");
    }

    /**
     * 新增数字提示
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数字提示
     */
    @RequiresPermissions("jiaqin:numbertips:add")
    @Log(title = "数字提示", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NumberTips numberTips)
    {
        return toAjax(numberTipsService.insertNumberTips(numberTips));
    }

    /**
     * 修改数字提示
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        NumberTips numberTips = numberTipsService.selectNumberTipsById(id);
        mmap.put("numberTips", numberTips);
        return prefix + "/edit";
    }

    /**
     * 修改保存数字提示
     */
    @RequiresPermissions("jiaqin:numbertips:edit")
    @Log(title = "数字提示", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NumberTips numberTips)
    {
        return toAjax(numberTipsService.updateNumberTips(numberTips));
    }

    /**
     * 删除数字提示
     */
    @RequiresPermissions("jiaqin:numbertips:remove")
    @Log(title = "数字提示", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(numberTipsService.deleteNumberTipsByIds(ids));
    }
}
